package com.wondedDream.service.impl;

import com.wondedDream.model.UserPracticeRecord;
import com.wondedDream.repository.UserPracticeRecordRepository;
import com.wondedDream.service.UserPracticeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserPracticeRecordServiceImpl implements UserPracticeRecordService {

    @Autowired
    private UserPracticeRecordRepository userPracticeRecordRepository;

    @Override
    public UserPracticeRecord saveUserPracticeRecord(UserPracticeRecord record) {
        return userPracticeRecordRepository.save(record);
    }

    @Override
    public UserPracticeRecord getUserPracticeRecordById(Integer id) {
        return userPracticeRecordRepository.findById(id).orElse(null);
    }

    @Override
    public List<UserPracticeRecord> getUserPracticeRecordsByUserId(Integer userId) {
        return userPracticeRecordRepository.findByUserId(userId);
    }

    @Override
    public List<UserPracticeRecord> getUserPracticeRecordsByPracticeQuestionId(Integer practiceQuestionId) {
        return userPracticeRecordRepository.findByPracticeQuestionId(practiceQuestionId);
    }

    @Override
    public List<UserPracticeRecord> findDistinctPracticeIdsByOpenid(String userOpenId) {
        return userPracticeRecordRepository.findDistinctPracticeIdsByOpenid(userOpenId);
    }
}